<template>
  <div class="content">
    <div class="content-header">
      <div v-if="back" class="content-back" @click="handelBack">
        <el-icon><arrow-left-bold /></el-icon>
        <span>返回</span>
        <span>|</span>
      </div>
      <div class="content-title">
        <slot name="title">
          {{ title }}
        </slot>
        <span class="sub-title">
          <slot name="sub-title"></slot>
        </span>
      </div>
      <div class="content-extra">
        <slot name="extra"></slot>
      </div>
    </div>
    <div class="top">
      <slot name="top"></slot>
    </div>
    <div class="all-content">
      <div class="white" :style="styleContent">
        <MainContentTabBarWrapper v-if="!!$slots['tab-bar']">
          <slot name="tab-bar"></slot>
        </MainContentTabBarWrapper>
        <MainContentSearchBarWrapper v-if="!!$slots['search-bar']">
          <slot name="search-bar"></slot>
        </MainContentSearchBarWrapper>
        <MainContentActionsWrapper v-if="!!$slots['actions-bar']">
          <slot name="actions-bar"></slot>
        </MainContentActionsWrapper>
        <div v-if="content" class="content-slot" :class="{ 'content-slot-bg': defaultContentSlot }">
          <slot></slot>
        </div>
      </div>
    </div>

    <div class="fix-bottom">
      <slot name="fixed-bottom"></slot>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: "MainContent",
};
</script>

<script lang="ts" setup>
import MainContentTabBarWrapper from "@/components/MainContentTabBarWrapper.vue";
import MainContentActionsWrapper from "@/components/MainContentActionsWrapper.vue";

const router = useRouter();
const func = defineProps({
  defaultContentSlot: {
    type: Boolean,
    default: true,
  },
  content: {
    type: Boolean,
    default: true,
  },
  back: {
    type: Boolean,
    default: false,
  },
  backFunc: {
    type: Boolean,
    default: false,
  },
  title: {
    type: String,
    default: "",
  },
  styleContent: {
    type: Object,
    default: () => ({}),
  }
});
let emits = defineEmits<{ (e: "back"): void }>();
const handelBack = () => {
  if (func.backFunc) {
    emits("back");
  } else {
    router.back();
  }
};
</script>

<style lang="scss" scoped>
.content {
  margin: 0;
  min-height: 300px;

  .content-header {
    padding: 0 30px;
    box-sizing: border-box;
    margin-bottom: 20px;
    height: 60px;
    line-height: 60px;
    font-size: 20px;
    background: #fff;
    display: flex;
    align-items: center;
    box-shadow: 0px 1px 12px 0px rgba(0, 0, 0, 0.06),
      inset 0px -1px 0px 0px #ebedf0;

    .content-title {
      font-weight: 700;
      color: #303133;
      flex: 1;
      // .sub-title {
      //   font-weight: 400;
      //   font-size: 12px;
      //   color: #909399;
      // }
    }

    .content-back {
      width: 80px;
      display: flex;
      font-size: 14px;
      color: #606265;
      align-items: center;
      cursor: pointer;

      :deep(.el-icon) {
        margin-right: 7px;
        color: #606265;
      }

      span {
        margin-right: 10px;
      }
    }
  }

  .top {
    margin: 20px 20px 0px 20px;
  }

  .all-content {
    margin: 20px 20px 20px 20px;
    min-height: calc(100vh - 180px);
    border-radius: 4px;
    box-shadow: 0px 2px 12px 0px rgb(0 0 0 / 10%);

    .white {
      width: 100%;
      height: 100%;
      background: #ffffff;
      // box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.1);
      padding: 20px;
      box-sizing: border-box;
    }
  }

  .content-slot-bg {
    //background: #ffffff;
    //padding: 0px 20px 20px;
    overflow: auto;
    // min-height: calc(100vh - 200px);
  }

  .tab-bar-wrapper {
    //padding: 0 20px;
    margin-bottom: 20px;
  }

  .search-bar-wrapper {
    margin-bottom: 20px;
  }
}

:deep(.el-tabs__header) {
  margin: 0 0 24px;

  .el-tabs__item {
    height: 36px;
    line-height: 36px;
  }
}

:deep(.el-tabs__nav-wrap) {
  &::after {
    background-color: transparent;
  }
}

.fix-bottom {
  position: sticky;
  bottom: 0;
  background: white;
  box-shadow: var(--el-box-shadow-dark);
  z-index: var(--el-index-normal);
}
</style>
